package com.ae.shield.common.items.util;

import net.minecraft.item.ItemStack;
import net.minecraft.nbt.INBT;
import net.minecraft.nbt.ListNBT;

public final class ItemNBTHelper {
    public static void setList(ItemStack itemStack, String tagName, ListNBT value){
        itemStack.getOrCreateTag().put(tagName, value);
    }

    public static ListNBT getList(ItemStack itemStack, String tagName, int objtype, ListNBT defaultValue){
        return isContainTag(itemStack, tagName) ? itemStack.getOrCreateTag().getList(tagName, objtype) : defaultValue;
    }

    public static void setInt(ItemStack itemStack, String tagName, int value) {
        itemStack.getOrCreateTag().putInt(tagName, value);
    }

    public static int getInt(ItemStack itemStack, String tagName, int defaultValue) {
        return isContainTag(itemStack, tagName) ? itemStack.getOrCreateTag().getInt(tagName) : defaultValue;
    }

    public static void setDouble(ItemStack itemStack, String tagName, double value) {
        itemStack.getOrCreateTag().putDouble(tagName, value);
    }

    public static double getDouble(ItemStack itemStack, String tagName, double defaultValue) {
        return isContainTag(itemStack, tagName) ? itemStack.getOrCreateTag().getDouble(tagName) : defaultValue;
    }

    public static void setLong(ItemStack itemStack, String tagName, long value) {
        itemStack.getOrCreateTag().putLong(tagName, value);
    }

    public static long getLong(ItemStack itemStack, String tagName, long defaultValue) {
        return isContainTag(itemStack, tagName) ? itemStack.getOrCreateTag().getLong(tagName) : defaultValue;
    }

    public static void setFloat(ItemStack itemStack, String tagName, float value) {
        itemStack.getOrCreateTag().putFloat(tagName, value);
    }

    public static float getFloat(ItemStack itemStack, String tagName, float defaultValue) {
        return isContainTag(itemStack, tagName) ? itemStack.getOrCreateTag().getFloat(tagName) : defaultValue;
    }

    public static void setLongArray(ItemStack itemStack, String tagName, long[] value) {
        itemStack.getOrCreateTag().putLongArray(tagName, value);
    }

    public static long[] getLongArray(ItemStack itemStack, String tagName, long[] defaultValue) {
        return isContainTag(itemStack, tagName) ? itemStack.getOrCreateTag().getLongArray(tagName) : defaultValue;
    }

    public static void setBoolean(ItemStack itemStack, String tagName, boolean value) {
        itemStack.getOrCreateTag().putBoolean(tagName, value);
    }

    public static boolean getBoolean(ItemStack itemStack, String tagName, boolean defaultValue) {
        return isContainTag(itemStack, tagName) ? itemStack.getOrCreateTag().getBoolean(tagName) : defaultValue;
    }

    public static void setString(ItemStack itemStack, String tagName, String value) {
        itemStack.getOrCreateTag().putString(tagName, value);
    }

    public static String getString(ItemStack itemStack, String tagName, String defaultValue) {
        return isContainTag(itemStack, tagName) ? itemStack.getOrCreateTag().getString(tagName) : defaultValue;
    }

    public static void setIntArray(ItemStack itemStack, String tagName, int[] value) {
        itemStack.getOrCreateTag().putIntArray(tagName, value);
    }

    public static int[] getIntArray(ItemStack itemStack, String tagName, int[] defaultValue) {
        return isContainTag(itemStack, tagName) ? itemStack.getOrCreateTag().getIntArray(tagName) : defaultValue;
    }

    public static void setByte(ItemStack itemStack, String tagName, byte value) {
        itemStack.getOrCreateTag().putByte(tagName, value);
    }

    public static Byte getByte(ItemStack itemStack, String tagName, Byte defaultValue) {
        return isContainTag(itemStack, tagName) ? itemStack.getOrCreateTag().getByte(tagName) : defaultValue;
    }

    public static void setByteArray(ItemStack itemStack, String tagName, byte[] value) {
        itemStack.getOrCreateTag().putByteArray(tagName, value);
    }

    public static byte[] getByteArray(ItemStack itemStack, String tagName, byte[] defaultValue) {
        return isContainTag(itemStack, tagName) ? itemStack.getOrCreateTag().getByteArray(tagName) : defaultValue;
    }

    public static void setNBT(ItemStack itemStack, String tagName, INBT nbt){
        itemStack.getOrCreateTag().put(tagName, nbt);
    }

    public static INBT getNBT(ItemStack itemStack, String tagName, INBT defaultValue) {
        return isContainTag(itemStack, tagName) ? itemStack.getOrCreateTag().get(tagName) : defaultValue;
    }

    public static boolean isContainTag(ItemStack itemStack, String tagName) {
        return itemStack.getOrCreateTag().contains(tagName);
    }
}
